import {ref,computed} from "vue"
import {useErpUserStore} from "@/store/modules/usererp.js";

export function useSzDetail(crmOption) {

  const detailData = ref(null)
  // 从store中拿到crm权限
  const crm = computed(() => {
    const erpUserStore = useErpUserStore();
    return erpUserStore.crm
  })


  // 能否查看详情
  const canShowDetail = computed(() => {
    console.log("canShowDetail")
    console.log("canShowDetail", detailData)
    console.log("canShowDetail", detailData.value?.dataAuth)
    if (detailData.value && detailData.value?.dataAuth === 0) {
      return false
    }
    console.log("canShowDetail2", detailData)
    console.log("canShowDetail2", crm.value)
    console.log("canShowDetail2", crmOption.crmType)
    console.log("canShowDetail2", crm.value[crmOption.crmType].read)

    return crm.value && crm.value[crmOption.crmType] && crm.value[crmOption.crmType].read
  })

  /**
   * isSeas 是从公海模块传入的 配合详情is_pool字段确定
   */
  const isSeasDetail = computed(() => {
    if (detailData.value && detailData.value.hasOwnProperty('isPool')) {
      return detailData.value.isPool == 1
    }
    return crmOption.isSeas
  })


  return {detailData,canShowDetail, isSeasDetail}
}